<template>
	<view class="content">
		<u-form label-position="left" label-width=180>
			<u-form-item>
				<u-button size="mini" @click="sign">签名</u-button>
				<view class="sign-image-bar">
					<image class="sign-image" :src="signSrc" mode=""></image>
				</view>
			</u-form-item>
		</u-form>
		<u-button class="bottom" type="primary" :disabled="disabled" :loading="loading"
			@click="submit">保存</u-button>
			
		<view class="sign-component">
			<!-- 签名组件 -->
			<qianming @getImg="getImg" @close="close" v-show="showSign" ref="QM" class="QMstyle"></qianming>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				disabled: false,
				loading: false,

				// 签名组件
				showSign: false, // 签名展示
				signSrc: vk.getVuex("$user.userInfo.sign"),
			}
		},
		onLoad(options) {
			this.init(options);
		},
		methods: {
			// 页面数据初始化函数
			init(options = {}) {
				console.log("init: ", options);
				if (vk.pubfn.isNull(vk.getVuex("$user.userInfo"))) {
					this.login();
				}
			},
			// 登录
			login() {
				uni.navigateTo({
					url: "/pages/userCenter/login/index/index",
					events: {
						loginSuccess: () => {
							// 随便修改一下data值，刷新页面绑定值。  也可以 this.userInfo = vk.getVuex('$user.salesInfo');
							this.refreshTime = new Date().getTime();
						}
					}
				})
			},
			submit() {
				if (!this.signSrc) {
					vk.alert("请电子签名")
					return false
				}

				this.disabled = true;
				this.loading = true;

				let dataJson = {
					sign: this.signSrc,
				};
				vk.callFunction({
					url: this.$api.RegisterProfile,
					loading: true,
					data: {
						_id: vk.getVuex("$user.userInfo._id"),
						sign: this.signSrc,
					},
					success: (res) => {
						vk.toast('保存成功');
						vk.setVuex("$user.userInfo.sign", this.signSrc);
						setTimeout(() => {
							vk.navigateBack();
						}, 1000);
					}
				})
			},
			sign() {
				this.showSign = true;
			},
			// 签名回调图片
			getImg(e) {
				console.log('签名', e)
				this.showSign = false;
				this.signSrc = e;
			},
			// 关闭签名
			close() {
				this.showSign = false;
			},
		}
	}
</script>

<style>

</style>